package io.gitee.twoke.generator.engine.impl.generate.processor;

import io.gitee.twoke.generator.engine.impl.generate.output.OutputEntity;
import io.gitee.twoke.generator.engine.impl.generate.output.OutputExecutor;
import org.apache.velocity.app.VelocityEngine;

import java.util.List;
import java.util.stream.Stream;

public class SimpleTemplateGenerator extends AbstractTemplateGenerator {

    private OutputExecutor executor;
    private boolean isParallel = false;

    public SimpleTemplateGenerator(VelocityEngine engine, OutputExecutor executor) {
        super(engine);
        this.executor = executor;
    }

    public boolean isParallel() {
        return isParallel;
    }

    public void setParallel(boolean parallel) {
        isParallel = parallel;
    }
    public void enableParallel() {
        this.setParallel(true);
    }

    public void disableParallel() {
        this.setParallel(false);
    }

    @Override
    protected void generateFile(List<OutputEntity> data) {
        Stream<OutputEntity> outputEntityStream = isParallel ? data.parallelStream() : data.stream();
        outputEntityStream.forEach(executor::execute);
    }
}
